/*
 * Filename:    AuditDispatchController.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014-11-10
 */
package com.paic.mhis.hcpms.audit.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.audit.biz.service.ICaseCommonService;
import com.paic.mhis.hcpms.audit.dto.AuditInsuranceInfoDTO;
import com.paic.mhis.hcpms.audit.dto.AuditMedicalInfoDTO;
import com.paic.mhis.hcpms.audit.dto.AuditOpinionDTO;
import com.paic.mhis.hcpms.audit.dto.AuditPointCutTempDTO;
import com.paic.mhis.hcpms.audit.dto.AuditiStaffInfoDTO;
import com.paic.mhis.hcpms.audit.dto.CaseCommonRequestDTO;
import com.paic.mhis.hcpms.audit.dto.CommonInsureanceDTO;
import com.paic.mhis.hcpms.audit.dto.CommonMedicalDTO;
import com.paic.mhis.hcpms.audit.dto.CommonStaffDTO;
import com.paic.pafa.appclient.annotation.BizServicesProxy;

/**
 * 案件审核的controller
 * 
 * @author EX-WANGKUI001
 * 
 */
@Controller
@RequestMapping("/caseCommonDispatch/")
public class CaseCommonController {
	private static final Logger logger = Logger
			.getLogger(CaseCommonController.class);

	@BizServicesProxy(beanName = "caseCommonServiceImpl")
	private ICaseCommonService caseCommonService;

	/**
	 * 根据taskCode,taskType,opinionType
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("loadDispatchInfo.do")
	@ResponseBody
	public AuditOpinionDTO loadDispatchInfo(HttpServletRequest request) {
		String taskCode = request.getParameter("taskCode");
		String taskType = request.getParameter("taskType");
		String opinionType = request.getParameter("opinionType");
		AuditOpinionDTO bean = this.caseCommonService.queryDispatchInfo(
				taskCode, taskType, opinionType);
		return bean;

	}

	/**
	 * 保存
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping("saveMedicalCommonInfo.do")
	@ResponseBody
	public Map<String, Object> saveMedicalCommonInfo(@ModelAttribute
	CaseCommonRequestDTO vo, HttpServletRequest request) {
		UserDetails user = (UserDetails) request.getSession().getAttribute(
				"user");

		Map<String, Object> map = new HashMap<String, Object>();
		try {
			this.caseCommonService.saveMedicalCommonInfo(vo, user);
			map.put("flag", true);
			map.put("msg", "操作成功");
		} catch (Exception es) {
			logger.info(es.getMessage());
			map.put("flag", false);
			map.put("msg", es.getMessage());
		}

		return map;
	}

	/**
	 * 暂存
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping("saveAuditTargetInfo.do")
	@ResponseBody
	public Map<String, Object> saveAuditTargetInfo(@ModelAttribute
	CaseCommonRequestDTO vo, HttpServletRequest request) {
		UserDetails user = (UserDetails) request.getSession().getAttribute(
				"user");
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			this.caseCommonService.saveAuditTargetInfo(vo, user);
			map.put("flag", true);
			map.put("msg", "操作成功");
		} catch (Exception es) {
			logger.info(es.getMessage());
			map.put("flag", false);
			map.put("msg", es.getMessage());
		}

		return map;
	}

	@RequestMapping("loadCaseCommonMedical.do")
	@ResponseBody
	public CommonMedicalDTO loadCaseCommonMedical(@ModelAttribute
	AuditMedicalInfoDTO vo, HttpServletRequest request) {

		int page = vo.getPage();
		int pageSize = vo.getPageSize();

		int start = (page - 1) * pageSize;
		int end = start + pageSize;
		vo.setEnd(end);
		vo.setStart(start);
		return this.caseCommonService.queryCommonMedicalBean(vo);

	}

	@RequestMapping("loadCaseCommonStaff.do")
	@ResponseBody
	public CommonStaffDTO loadCaseCommonStaff(@ModelAttribute
	AuditiStaffInfoDTO vo, HttpServletRequest request) {

		int page = vo.getPage();
		int pageSize = vo.getPageSize();

		int start = (page - 1) * pageSize;
		int end = start + pageSize;
		vo.setEnd(end);
		vo.setStart(start);

		return this.caseCommonService.queryCommonStaffBean(vo);

	}

	@RequestMapping("loadCaseCommonInsurance.do")
	@ResponseBody
	public CommonInsureanceDTO loadCaseCommonInsurance(@ModelAttribute
	AuditInsuranceInfoDTO vo, HttpServletRequest request) {

		int page = vo.getPage();
		int pageSize = vo.getPageSize();

		int start = (page - 1) * pageSize;
		int end = start + pageSize;
		vo.setEnd(end);
		vo.setStart(start);

		return this.caseCommonService.queryCommonInsureanceBean(vo);

	}

	@RequestMapping("loadAuditPointCutTemp.do")
	@ResponseBody
	public List<AuditPointCutTempDTO> loadAuditPointCutTemp(@ModelAttribute
	AuditPointCutTempDTO dto, HttpServletRequest request) {
		return caseCommonService.loadAuditPointCutTemp(dto);
	}

}
